

#include <cegfx/ceprojector.h>


ceProjector::ceProjector (const iViewport* viewport)
	: l (-1)
	, r (1)
	, b (-1)
	, t (1)
	, n (1)
	, f (1024)
	, viewport (viewport)
{
	IQF_CONSTRUCT;
	UpdateMatrix();
}

IQF_IMPLEMENTATION_BEGIN(ceProjector);
IQF_IMPLEMENTATION_END();

void ceProjector::SetViewport (const iViewport* viewport)
{
	this->viewport = viewport;
}

const iViewport* ceProjector::GetViewport () const
{
	return viewport;
}

void ceProjector::SetLeft (float l)
{
	this->l = l;
}

float ceProjector::GetLeft () const
{
	return l;
}

void ceProjector::SetRight (float r)
{
	this->r = r;
}

float ceProjector::GetRight () const
{
	return r;
}

void ceProjector::SetBottom (float b)
{
	this->b = b;
}

float ceProjector::GetBottom () const
{
	return b;
}

void ceProjector::SetTop (float t)
{
	this->t = t;
}

float ceProjector::GetTop () const
{
	return t;
}

void ceProjector::SetNear (float n)
{
	this->n = n;
}

float ceProjector::GetNear () const
{
	return n;
}

void ceProjector::SetFar (float f)
{
	this->f = f;
}

float ceProjector::GetFar () const
{
	return f;
}

void ceProjector::Update (float angle)
{
	float aspect = (float) this->viewport->GetHeight() / (float) this->viewport->GetWidth();

  r = tanf (angle * (float) D3DX_PI / 180.0f) * n;
  l = -r;

  t = aspect * t;
  b = -t;

	UpdateMatrix ();
}


void ceProjector::UpdateMatrix ()
{
	D3DXMatrixPerspectiveOffCenterLH (&matrix, l, r, b, t, n, f);
}

const D3DXMATRIX& ceProjector::GetMatrix () const
{
	return matrix;
}

